<template>
    <view class="page">
        <view class="addresinfo" v-for="(v, i) in address_list" :key="i">
			<view class="info" @click='clickToBack(v.id)'>
				<view class="flexRowC" style="margin-bottom: 10rpx;">
					
					<view >
					    {{v.ptel}}
					</view>
				</view>
				<view class="flexRowC">
					<image style="width: 28rpx; height: 34rpx; margin-right: 20rpx;" src="../../static/address.png" mode=""></image>
					<view class="" style="font-size: 26rpx;">
					    {{v.pplace}}
					</view>
				</view>
			</view>
            <view  class="set flexRowC" style="justify-content: space-between;">
                <!-- <view class="">
                    <u-radio-group v-model="default_id" @change="doDefault(v.id)">
                        <u-radio active-color="#EA6752" shape="circle" :name="v.id">设置为默认地址</u-radio>
                    </u-radio-group>
                </view> -->
                <!-- <view class="rightset flexRowC">
					<view class="setBlock" @click="editAddress(v.id)">
						<text>修改</text>
					</view>
					<view class="setBlock" @click="confirmDel(v.id)">
						<text>删除</text>
					</view>
                    
                </view> -->
            </view>
        </view>
        <view class="" v-if="empty_show">
          
			<u-empty text="暂无数据" src='/static/task/no-data.png'></u-empty>
        </view>
		<view class="fixedbtn">
			<button type="default" class="savebtn" @click="editAddress(0)">+添加新地址</button>
		</view>
        
        <view>
            <u-modal v-model="confirm_show" content="确定删除该信息么？" :show-cancel-button="true" @confirm="doDel"></u-modal>
        </view>
    </view>
    
</template>

<script>
    export default {
        components: {
            
        },
        computed: {
            default_address: function(val, id){
                if(val === 1) return id
                else return 0
            } 
        },
        data() {
            return {
                default_id: 0,
                confirm_show: false,
                del_id: 0,
                empty_show: false,
                address_list: [
                    // {
                    //     address_username: 'a敏',
                    //     address_tel: '15307311714',
                    //     province: '湖南省',
                    //     city: '长沙市',
                    //     area: '天心区',
                    //     detail: '恒力卡瑞尔2507',
                    //     address_detail: '湖南省长沙市天心区恒力卡瑞尔2507',
                    //     id: 1,
                    //     is_default: 1,
                    // },
                    // {
                    //     address_username: 'a敏',
                    //     address_tel: '15307311714',
                    //     province: '湖南省',
                    //     city: '长沙市',
                    //     area: '天心区',
                    //     detail: '恒力卡瑞尔2507',
                    //     address_detail: '湖南省长沙市天心区恒力卡瑞尔2507',
                    //     id: 2,
                    //     is_default: 0,
                    // }
                ],
                task_id: 0,
                page_from: '',
                user_card_id: 0,
            }
        },
        onLoad(options) {
            this.page_from = options.from || '';
            this.task_id = options.task_id || 0;
            this.user_card_id = options.user_card_id || 0;
            
        },
        onShow() {
            this.getAddressList();
        },
        methods: {
            getAddressList() {
                this.$http.post('/goods_user_position/list',{}).then(res => {
                    this.address_list = res.list;
                    // this.default_id = res.data.default_id;
                    if(this.address_list.length === 0) {
                      this.empty_show = true;
                    }else{
                      this.empty_show = false;
                    }
                }).catch(res=>{
                    this.empty_show = true;
                })
            },
            doDefault(id) {
                // console.log(id)
                this.$http.put('/set_default/'+id, {is_default:1, id: id}).then(res => {
                    console.log(res.data)
					
                    this.getAddressList();
                })
            },
            editAddress(id=0) {
                uni.navigateTo({
                    url: '/pages/enter/editAddress?id='+id
                })
            },
            clickToBack(id = 0) {
                if(this.page_from === '') {
                    return false;
                }
                if(this.page_from === 'join') {
		            
                    uni.redirectTo({
                        url: '/pages/task/join?task_id='+this.task_id+"&user_address_id="+id+"&user_card_id="+this.user_card_id,
                    })
                }
                
            },
            confirmDel(id) {
                this.confirm_show = true;
                this.del_id = id
            },
            doDel() {
                this.$http.delete('/address/'+this.del_id).then(res => {
                    this.address_list = []
					this.getAddressList();
                })
            }
        },
    }
</script>

<style lang="scss" scoped>
    /deep/ .u-radio__label{ font-size: $uni-font-size-base;}
	.page{
		width: 750rpx;
		min-height: 100%;
		padding-top: 30rpx;
		padding-bottom: 150rpx;
	}
	.addresinfo{
		width: 690rpx;
		height: 250rpx;
		margin-bottom: 27rpx;
		margin-left: 28rpx;
		background-color: #fff;
		border-radius: 10rpx;
		color: #fff;
		font-size: 28rpx;
		.info{
			height: 140rpx;
			width: 100%;
			padding: 30rpx;
			background-image: linear-gradient(to right, #EA6652 , #F1874E);
		}
		.set{
			width: 100%;
			height: 110rpx;
			padding: 0 38rpx;
			.setBlock{
				font-size: 24rpx;
				margin-left: 48rpx;
				width: 82rpx;
				height: 42rpx;
				line-height: 42rpx;
				text-align: center;
				color: #EA6752;
				border: 1rpx solid #EA6752;
				border-radius: 10rpx;
			}
		}
	}
	.fixedbtn{
		position: fixed;
		bottom: 0;
		left: 0;
	}
	.savebtn{
		width: 750rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: #fff;
		font-size: 34rpx;
		border-radius: 0;
		
		background-image: linear-gradient(to right, #EA6652 , #F1874E);
	}
</style>

